﻿using System.Collections.Generic;
using System.Linq;
using UpdateControls.Correspondence;
using UpdateControls.Correspondence.Mementos;
using System;

/**
/ For use with http://graphviz.org/
digraph "SurveySez.Model"
{
    rankdir=BT
    EmceeSurvey -> Emcee
    EmceeSurvey -> Survey
    EmceeSurveyDelete -> EmceeSurvey
    EmceeGame -> Emcee
    EmceeGame -> Game
    EmceeGameDelete -> EmceeGame
    Response -> Survey
    ResponseDelete -> Response
    ResponseAnswer -> Response
    ResponseAnswer -> ResponseAnswer [label="  *"]
    ResponseOrder -> Response
    ResponseOrder -> ResponseOrder [label="  *"]
    SurveyQuestion -> Survey
    SurveyQuestion -> SurveyQuestion [label="  *"]
    GameName -> Game
    GameName -> GameName [label="  *"]
    GameSurvey -> Game
    GameSurvey -> Survey
    GameSurveyDelete -> GameSurvey
}
**/

namespace SurveySez.Model
{
    [CorrespondenceType]
    public partial class Emcee : CorrespondenceFact
    {
        // Roles

        // Queries
        public static Query QueryEmceeSurveys = new Query()
            .JoinSuccessors(EmceeSurvey.RoleEmcee, Condition.WhereIsEmpty(EmceeSurvey.QueryIsCurrent)
            )
            ;
        public static Query QueryEmceeGames = new Query()
            .JoinSuccessors(EmceeGame.RoleEmcee, Condition.WhereIsEmpty(EmceeGame.QueryIsCurrent)
            )
            ;

        // Predecessors

        // Unique
        [CorrespondenceField]
        private Guid _unique;

        // Fields

        // Results
        private Result<EmceeSurvey> _emceeSurveys;
        private Result<EmceeGame> _emceeGames;

        // Business constructor
        public Emcee(
            )
        {
            _unique = Guid.NewGuid();
            InitializeResults();
        }

        // Hydration constructor
        private Emcee(FactMemento memento)
        {
            InitializeResults();
        }

        // Result initializer
        private void InitializeResults()
        {
            _emceeSurveys = new Result<EmceeSurvey>(this, QueryEmceeSurveys);
            _emceeGames = new Result<EmceeGame>(this, QueryEmceeGames);
        }

        // Predecessor access

        // Field access

        // Query result access
        public IEnumerable<EmceeSurvey> EmceeSurveys
        {
            get { return _emceeSurveys; }
        }
        public IEnumerable<EmceeGame> EmceeGames
        {
            get { return _emceeGames; }
        }

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class EmceeSurvey : CorrespondenceFact
    {
        // Roles
        public static Role<Emcee> RoleEmcee = new Role<Emcee>("emcee");
        public static Role<Survey> RoleSurvey = new Role<Survey>("survey");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(EmceeSurveyDelete.RoleEmceeSurvey)
            ;

        // Predecessors
        private PredecessorObj<Emcee> _emcee;
        private PredecessorObj<Survey> _survey;

        // Fields

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public EmceeSurvey(
            Emcee emcee
            ,Survey survey
            )
        {
            InitializeResults();
            _emcee = new PredecessorObj<Emcee>(this, RoleEmcee, emcee);
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, survey);
        }

        // Hydration constructor
        private EmceeSurvey(FactMemento memento)
        {
            InitializeResults();
            _emcee = new PredecessorObj<Emcee>(this, RoleEmcee, memento);
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Emcee Emcee
        {
            get { return _emcee.Fact; }
        }
        public Survey Survey
        {
            get { return _survey.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class EmceeSurveyDelete : CorrespondenceFact
    {
        // Roles
        public static Role<EmceeSurvey> RoleEmceeSurvey = new Role<EmceeSurvey>("emceeSurvey");

        // Queries

        // Predecessors
        private PredecessorObj<EmceeSurvey> _emceeSurvey;

        // Fields

        // Results

        // Business constructor
        public EmceeSurveyDelete(
            EmceeSurvey emceeSurvey
            )
        {
            InitializeResults();
            _emceeSurvey = new PredecessorObj<EmceeSurvey>(this, RoleEmceeSurvey, emceeSurvey);
        }

        // Hydration constructor
        private EmceeSurveyDelete(FactMemento memento)
        {
            InitializeResults();
            _emceeSurvey = new PredecessorObj<EmceeSurvey>(this, RoleEmceeSurvey, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        }

        // Predecessor access
        public EmceeSurvey EmceeSurvey
        {
            get { return _emceeSurvey.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class EmceeGame : CorrespondenceFact
    {
        // Roles
        public static Role<Emcee> RoleEmcee = new Role<Emcee>("emcee");
        public static Role<Game> RoleGame = new Role<Game>("game");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(EmceeGameDelete.RoleEmceeGame)
            ;

        // Predecessors
        private PredecessorObj<Emcee> _emcee;
        private PredecessorObj<Game> _game;

        // Fields

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public EmceeGame(
            Emcee emcee
            ,Game game
            )
        {
            InitializeResults();
            _emcee = new PredecessorObj<Emcee>(this, RoleEmcee, emcee);
            _game = new PredecessorObj<Game>(this, RoleGame, game);
        }

        // Hydration constructor
        private EmceeGame(FactMemento memento)
        {
            InitializeResults();
            _emcee = new PredecessorObj<Emcee>(this, RoleEmcee, memento);
            _game = new PredecessorObj<Game>(this, RoleGame, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Emcee Emcee
        {
            get { return _emcee.Fact; }
        }
        public Game Game
        {
            get { return _game.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class EmceeGameDelete : CorrespondenceFact
    {
        // Roles
        public static Role<EmceeGame> RoleEmceeGame = new Role<EmceeGame>("emceeGame");

        // Queries

        // Predecessors
        private PredecessorObj<EmceeGame> _emceeGame;

        // Fields

        // Results

        // Business constructor
        public EmceeGameDelete(
            EmceeGame emceeGame
            )
        {
            InitializeResults();
            _emceeGame = new PredecessorObj<EmceeGame>(this, RoleEmceeGame, emceeGame);
        }

        // Hydration constructor
        private EmceeGameDelete(FactMemento memento)
        {
            InitializeResults();
            _emceeGame = new PredecessorObj<EmceeGame>(this, RoleEmceeGame, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        }

        // Predecessor access
        public EmceeGame EmceeGame
        {
            get { return _emceeGame.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class Response : CorrespondenceFact
    {
        // Roles
        public static Role<Survey> RoleSurvey = new Role<Survey>("survey");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(ResponseDelete.RoleResponse)
            ;
        public static Query QueryCurrentAnswers = new Query()
            .JoinSuccessors(ResponseAnswer.RoleResponse, Condition.WhereIsEmpty(ResponseAnswer.QueryIsCurrent)
            )
            ;
        public static Query QueryCurrentOrders = new Query()
            .JoinSuccessors(ResponseOrder.RoleResponse, Condition.WhereIsEmpty(ResponseOrder.QueryIsCurrent)
            )
            ;

        // Predecessors
        private PredecessorObj<Survey> _survey;

        // Unique
        [CorrespondenceField]
        private Guid _unique;

        // Fields

        // Results
        private Result<ResponseAnswer> _currentAnswers;
        private Result<ResponseOrder> _currentOrders;
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public Response(
            Survey survey
            )
        {
            _unique = Guid.NewGuid();
            InitializeResults();
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, survey);
        }

        // Hydration constructor
        private Response(FactMemento memento)
        {
            InitializeResults();
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
            _currentAnswers = new Result<ResponseAnswer>(this, QueryCurrentAnswers);
            _currentOrders = new Result<ResponseOrder>(this, QueryCurrentOrders);
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Survey Survey
        {
            get { return _survey.Fact; }
        }

        // Field access

        // Query result access
        public IEnumerable<ResponseAnswer> CurrentAnswers
        {
            get { return _currentAnswers; }
        }
        public IEnumerable<ResponseOrder> CurrentOrders
        {
            get { return _currentOrders; }
        }

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class ResponseDelete : CorrespondenceFact
    {
        // Roles
        public static Role<Response> RoleResponse = new Role<Response>("response");

        // Queries

        // Predecessors
        private PredecessorObj<Response> _response;

        // Fields

        // Results

        // Business constructor
        public ResponseDelete(
            Response response
            )
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, response);
        }

        // Hydration constructor
        private ResponseDelete(FactMemento memento)
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        }

        // Predecessor access
        public Response Response
        {
            get { return _response.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class ResponseAnswer : CorrespondenceFact
    {
        // Roles
        public static Role<Response> RoleResponse = new Role<Response>("response");
        public static Role<ResponseAnswer> RolePrior = new Role<ResponseAnswer>("prior");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(ResponseAnswer.RolePrior)
            ;

        // Predecessors
        private PredecessorObj<Response> _response;
        private PredecessorList<ResponseAnswer> _prior;

        // Fields
        [CorrespondenceField]
        private string _answer;

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public ResponseAnswer(
            Response response
            ,IEnumerable<ResponseAnswer> prior
            ,string answer
            )
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, response);
            _prior = new PredecessorList<ResponseAnswer>(this, RolePrior, prior);
            _answer = answer;
        }

        // Hydration constructor
        private ResponseAnswer(FactMemento memento)
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, memento);
            _prior = new PredecessorList<ResponseAnswer>(this, RolePrior, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Response Response
        {
            get { return _response.Fact; }
        }
        public IEnumerable<ResponseAnswer> Prior
        {
            get { return _prior; }
        }
     
        // Field access
        public string Answer
        {
            get { return _answer; }
        }

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class ResponseOrder : CorrespondenceFact
    {
        // Roles
        public static Role<Response> RoleResponse = new Role<Response>("response");
        public static Role<ResponseOrder> RolePrior = new Role<ResponseOrder>("prior");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(ResponseOrder.RolePrior)
            ;

        // Predecessors
        private PredecessorObj<Response> _response;
        private PredecessorList<ResponseOrder> _prior;

        // Fields
        [CorrespondenceField]
        private float _order;

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public ResponseOrder(
            Response response
            ,IEnumerable<ResponseOrder> prior
            ,float order
            )
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, response);
            _prior = new PredecessorList<ResponseOrder>(this, RolePrior, prior);
            _order = order;
        }

        // Hydration constructor
        private ResponseOrder(FactMemento memento)
        {
            InitializeResults();
            _response = new PredecessorObj<Response>(this, RoleResponse, memento);
            _prior = new PredecessorList<ResponseOrder>(this, RolePrior, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Response Response
        {
            get { return _response.Fact; }
        }
        public IEnumerable<ResponseOrder> Prior
        {
            get { return _prior; }
        }
     
        // Field access
        public float Order
        {
            get { return _order; }
        }

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class Survey : CorrespondenceFact
    {
        // Roles

        // Queries
        public static Query QueryCurrentQuestions = new Query()
            .JoinSuccessors(SurveyQuestion.RoleSurvey, Condition.WhereIsEmpty(SurveyQuestion.QueryIsCurrent)
            )
            ;
        public static Query QueryResponses = new Query()
            .JoinSuccessors(Response.RoleSurvey, Condition.WhereIsEmpty(Response.QueryIsCurrent)
            )
            ;
        public static Query QueryGames = new Query()
            .JoinSuccessors(GameSurvey.RoleSurvey, Condition.WhereIsEmpty(GameSurvey.QueryIsCurrent)
            )
            .JoinPredecessors(GameSurvey.RoleGame)
            ;

        // Predecessors

        // Unique
        [CorrespondenceField]
        private Guid _unique;

        // Fields

        // Results
        private Result<SurveyQuestion> _currentQuestions;
        private Result<Response> _responses;
        private Result<Game> _games;

        // Business constructor
        public Survey(
            )
        {
            _unique = Guid.NewGuid();
            InitializeResults();
        }

        // Hydration constructor
        private Survey(FactMemento memento)
        {
            InitializeResults();
        }

        // Result initializer
        private void InitializeResults()
        {
            _currentQuestions = new Result<SurveyQuestion>(this, QueryCurrentQuestions);
            _responses = new Result<Response>(this, QueryResponses);
            _games = new Result<Game>(this, QueryGames);
        }

        // Predecessor access

        // Field access

        // Query result access
        public IEnumerable<SurveyQuestion> CurrentQuestions
        {
            get { return _currentQuestions; }
        }
        public IEnumerable<Response> Responses
        {
            get { return _responses; }
        }
        public IEnumerable<Game> Games
        {
            get { return _games; }
        }

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class SurveyQuestion : CorrespondenceFact
    {
        // Roles
        public static Role<Survey> RoleSurvey = new Role<Survey>("survey");
        public static Role<SurveyQuestion> RolePrior = new Role<SurveyQuestion>("prior");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(SurveyQuestion.RolePrior)
            ;

        // Predecessors
        private PredecessorObj<Survey> _survey;
        private PredecessorList<SurveyQuestion> _prior;

        // Fields
        [CorrespondenceField]
        private string _question;

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public SurveyQuestion(
            Survey survey
            ,IEnumerable<SurveyQuestion> prior
            ,string question
            )
        {
            InitializeResults();
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, survey);
            _prior = new PredecessorList<SurveyQuestion>(this, RolePrior, prior);
            _question = question;
        }

        // Hydration constructor
        private SurveyQuestion(FactMemento memento)
        {
            InitializeResults();
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, memento);
            _prior = new PredecessorList<SurveyQuestion>(this, RolePrior, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Survey Survey
        {
            get { return _survey.Fact; }
        }
        public IEnumerable<SurveyQuestion> Prior
        {
            get { return _prior; }
        }
     
        // Field access
        public string Question
        {
            get { return _question; }
        }

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class Game : CorrespondenceFact
    {
        // Roles

        // Queries
        public static Query QueryGameSurveys = new Query()
            .JoinSuccessors(GameSurvey.RoleGame, Condition.WhereIsEmpty(GameSurvey.QueryIsCurrent)
            )
            ;
        public static Query QueryCurrentNames = new Query()
            .JoinSuccessors(GameName.RoleGame, Condition.WhereIsEmpty(GameName.QueryIsCurrent)
            )
            ;

        // Predecessors

        // Unique
        [CorrespondenceField]
        private Guid _unique;

        // Fields

        // Results
        private Result<GameSurvey> _gameSurveys;
        private Result<GameName> _CurrentNames;

        // Business constructor
        public Game(
            )
        {
            _unique = Guid.NewGuid();
            InitializeResults();
        }

        // Hydration constructor
        private Game(FactMemento memento)
        {
            InitializeResults();
        }

        // Result initializer
        private void InitializeResults()
        {
            _gameSurveys = new Result<GameSurvey>(this, QueryGameSurveys);
            _CurrentNames = new Result<GameName>(this, QueryCurrentNames);
        }

        // Predecessor access

        // Field access

        // Query result access
        public IEnumerable<GameSurvey> GameSurveys
        {
            get { return _gameSurveys; }
        }
        public IEnumerable<GameName> CurrentNames
        {
            get { return _CurrentNames; }
        }

        // Predicate result access
    }
    
    [CorrespondenceType]
    public partial class GameName : CorrespondenceFact
    {
        // Roles
        public static Role<Game> RoleGame = new Role<Game>("game");
        public static Role<GameName> RolePrior = new Role<GameName>("prior");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(GameName.RolePrior)
            ;

        // Predecessors
        private PredecessorObj<Game> _game;
        private PredecessorList<GameName> _prior;

        // Fields
        [CorrespondenceField]
        private string _name;

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public GameName(
            Game game
            ,IEnumerable<GameName> prior
            ,string name
            )
        {
            InitializeResults();
            _game = new PredecessorObj<Game>(this, RoleGame, game);
            _prior = new PredecessorList<GameName>(this, RolePrior, prior);
            _name = name;
        }

        // Hydration constructor
        private GameName(FactMemento memento)
        {
            InitializeResults();
            _game = new PredecessorObj<Game>(this, RoleGame, memento);
            _prior = new PredecessorList<GameName>(this, RolePrior, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Game Game
        {
            get { return _game.Fact; }
        }
        public IEnumerable<GameName> Prior
        {
            get { return _prior; }
        }
     
        // Field access
        public string Name
        {
            get { return _name; }
        }

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class GameSurvey : CorrespondenceFact
    {
        // Roles
        public static Role<Game> RoleGame = new Role<Game>("game");
        public static Role<Survey> RoleSurvey = new Role<Survey>("survey");

        // Queries
        public static Query QueryIsCurrent = new Query()
            .JoinSuccessors(GameSurveyDelete.RoleGameSurvey)
            ;

        // Predecessors
        private PredecessorObj<Game> _game;
        private PredecessorObj<Survey> _survey;

        // Unique
        [CorrespondenceField]
        private Guid _unique;

        // Fields
        [CorrespondenceField]
        private float _order;

        // Results
        private Result<CorrespondenceFact> _isCurrent;

        // Business constructor
        public GameSurvey(
            Game game
            ,Survey survey
            ,float order
            )
        {
            _unique = Guid.NewGuid();
            InitializeResults();
            _game = new PredecessorObj<Game>(this, RoleGame, game);
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, survey);
            _order = order;
        }

        // Hydration constructor
        private GameSurvey(FactMemento memento)
        {
            InitializeResults();
            _game = new PredecessorObj<Game>(this, RoleGame, memento);
            _survey = new PredecessorObj<Survey>(this, RoleSurvey, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        _isCurrent = new Result<CorrespondenceFact>(this, QueryIsCurrent);
        }

        // Predecessor access
        public Game Game
        {
            get { return _game.Fact; }
        }
        public Survey Survey
        {
            get { return _survey.Fact; }
        }

        // Field access
        public float Order
        {
            get { return _order; }
        }

        // Query result access

        // Predicate result access
        public bool IsCurrent
        {
            get { return !_isCurrent.Any(); }
        }
    }
    
    [CorrespondenceType]
    public partial class GameSurveyDelete : CorrespondenceFact
    {
        // Roles
        public static Role<GameSurvey> RoleGameSurvey = new Role<GameSurvey>("gameSurvey");

        // Queries

        // Predecessors
        private PredecessorObj<GameSurvey> _gameSurvey;

        // Fields

        // Results

        // Business constructor
        public GameSurveyDelete(
            GameSurvey gameSurvey
            )
        {
            InitializeResults();
            _gameSurvey = new PredecessorObj<GameSurvey>(this, RoleGameSurvey, gameSurvey);
        }

        // Hydration constructor
        private GameSurveyDelete(FactMemento memento)
        {
            InitializeResults();
            _gameSurvey = new PredecessorObj<GameSurvey>(this, RoleGameSurvey, memento);
        }

        // Result initializer
        private void InitializeResults()
        {
        }

        // Predecessor access
        public GameSurvey GameSurvey
        {
            get { return _gameSurvey.Fact; }
        }

        // Field access

        // Query result access

        // Predicate result access
    }
    
}
